import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import elib.Kierownik;
import elib.Osoba;

@WebServlet("/EditKaraServlet")
public class EditKaraServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public EditKaraServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		//pobieranie sesji
		HttpSession session = request.getSession();
		//pobieranie parametrow z formularza
		String stawka = request.getParameter("stawka");
		String okres = request.getParameter("okres");
		if (session != null) {
			Osoba osoba = (Osoba) session.getAttribute("osoba");
			if (osoba != null && osoba instanceof Kierownik) {
				float stawka1=-1;
				int okres1=-1;
				if(stawka!=null && !stawka.equals("")) {
					try {
						stawka1 = Float.parseFloat(stawka);
					} catch(Exception e) {
						stawka1 = -1;
					}
				}
				if(okres!=null && !okres.equals("")) {
					try {
						okres1 = Integer.parseInt(okres);
					} catch(Exception e) {
						okres1 = -1;
					}
				}
				((Kierownik) osoba).ustawieniaKar(stawka1, okres1);
				response.sendRedirect("admin.jsp?page=editKara");
			} else
				response.sendRedirect("index.jsp");
		} else
			response.sendRedirect("index.jsp");
		out.close();
	}
}